<template>
	<view class="content">
		<view class="qr-con">
			<!-- #ifdef H5	 -->
			<view style="margin: 0 auto;margin-bottom: 62rpx;">
			<!-- #endif -->
				<!-- #ifdef MP-ALIPAY	 -->
				<view style="margin: 0 auto;">
				<!-- #endif -->
					<w-barcode :options="options" @generate="generate"></w-barcode>
					<!-- <tki-barcode ref="barcode" cid="qrcodeB" :val="patientId" :opations="opations" /> -->
				</view>
				<canvas id="qrcodeA" canvas-id="qrcodeA" style="width: 210px;height: 210px;"></canvas>
				<!-- <image src="../../static/img/qrcode.png" style="width: 438rpx;height: 438rpx;"></image> -->
				<view style="margin-top: 23rpx;">
					就诊时请出示就诊码进行就诊
				</view>
			</view>
		</view>
</template>

<script>
	import UQRCode from 'uqrcodejs';
	// import tkiBarcode from "@/components/tki-barcode/tki-barcode.vue"
	export default {
		data() {
			return {
				patientId: '',
				// #ifdef H5
				options: {
					width: 500,
					height: 100,
					code: '',
					text: {
						content: '',
						color: ['#999999'],
						position: 'bottom', //bottom
						size: 30,
						padding: 10
					}
				},
				// #endif
				// #ifdef MP-ALIPAY
				options: {
					width: 500,
					height: 100,
					code: '',
					text: {
						content: '',
						color: ['#999999'],
						position: 'bottom', //bottom
						size: 100,
						padding: 40
					}
				},
				// #endif
			}
		},
		// components: {
		// 	tkiBarcode
		// },
		onLoad(option) {
			console.log(option.patientId);
			this.patientId = option.patientId
			this.options.code = this.patientId
			this.options.text.content = this.patientId

		},
		mounted() {
			this.makeQrcode(this.patientId)
		},
		methods: {
			generate(val) {
				console.log(val);
			},
			makeQrcode(id) {
				// 获取uQRCode实例
				var qr = new UQRCode();
				console.log(qr);
				// 设置二维码内容
				qr.data = id;
				// 设置二维码大小，必须与canvas设置的宽高一致
				qr.size = 210;
				// 调用制作二维码方法
				qr.make();
				// 获取canvas上下文
				var canvasContext = uni.createCanvasContext('qrcodeA', this); // 如果是组件，this必须传入

				// 设置uQRCode实例的canvas上下文
				qr.canvasContext = canvasContext;
				// 调用绘制方法将二维码图案绘制到canvas上
				qr.drawCanvas();
			},
		}
	}
</script>

<style scoped lang="scss">
	.content {
		width: 100vw;
		/* #ifdef H5 */
		height: 100vh;
		// #endif
		/* #ifdef MP-ALIPAY */
		height: 100vh;
		// #endif
		background-image: url('#{$IMG_URL}bg_information_l.png');
		background-repeat: no-repeat;
		background-size: cover;
		color: #999999;
		font-size: 27rpx;
		padding-top: 100rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		box-sizing: border-box;
	}

	.qr-con {
		width: 688rpx;
		padding-top: 46rpx;
		padding-bottom: 200rpx;
		background: #FFFFFF;
		border-radius: 19rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>